package com.hang.controller;

import com.hang.common.BizException;
import com.hang.common.Result;
import com.hang.service.StudentService;
import com.hang.service.TeacherService;
import com.hang.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("login")
@AllArgsConstructor
@Api(tags = "登录接口")
public class LoginController {
    private TeacherService teacherService;
    private StudentService studentService;

    @ApiOperation(value = "教师登录端")
    @PostMapping("teacher")
    public Result teacherLogin(@RequestBody LoginVo loginVo){
        Map<String,Object> map;
        try {
            map = teacherService.login(loginVo);
        }catch (BizException be){
            return Result.fail().message("登录失败");
        }
        return Result.ok(map);
    }

    @ApiOperation(value = "学生端登录")
    @PostMapping("student")
    public Result studentLogin(@RequestBody LoginVo loginVo){
        Map<String,Object> map;
        try{
            map = studentService.login(loginVo);
        }catch (BizException be){
            return Result.fail().message("登录失败");
        }
        return Result.ok(map);
    }
}